home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / lib / dial / d_path.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-02-01  |  4.0 KB  |  165 lines

  1. # include  "d_proto.h"
  2. # include  "d_returns.h"
  3. #include <signal.h>
  4. # include  "d_syscodes.h"
  5.  
  6. /*  Jul 81  D. Crocker      convert maxlen>255 -> 255
  7.  */
  8.  
  9. /*
  10.  *     D_SNPATH
  11.  *
  12.  *     this routine is called to send a PATH packet.  it is used for both
  13.  *     XPATH and RPATH packets.
  14.  *
  15.  *     type -- the type of the packet to send (XPATH or RPATH)
  16.  *
  17.  *     ack -- the type of acknowledgement to wait for
  18.  *
  19.  *     ackwait -- the amount of time to wait for the acknowledgement
  20.  *
  21.  *     maxleng -- the maximum packet length for this path
  22.  *
  23.  *     bitvector -- the bit vector of illegal characters (local) for this
  24.  *                  path.
  25.  */
  26.  
  27. d_snpath(type, maxleng, bitvector)
  28.   char  type;
  29.   int  maxleng;
  30.   unsigned short bitvector[];
  31.     {
  32.     extern int  d_snseq;
  33.     register int  length, result;
  34.     char  packet[MAXPACKET + 2], txtbuf[LPATH];
  35.  
  36.     /*  assemble the text portion  */
  37.     if (maxleng > 255)            /* must fit into 8-bit field          */
  38.     {
  39. #ifdef D_LOG
  40.     d_log("d_snpath", "max packet len > 255 (%d)", maxleng);
  41. #endif D_LOG
  42.     maxleng = 255;            /* should be safe to trim it down     */
  43.     }
  44.     txtbuf[0] = d_tohex((maxleng >> 4) & 017);
  45.     txtbuf[1] = d_tohex(maxleng & 017);
  46.  
  47.     d_bldhvec(bitvector, &txtbuf[2]);
  48.  
  49.     /*  build the complete packet and send it  */
  50.     d_snseq = d_incseq(d_snseq);
  51.     length = d_bldpack(type, d_snseq, 1, txtbuf, packet);
  52.  
  53.     result = d_snpkt(type, packet, length);
  54.     return(result);
  55. }
  56.  
  57.  
  58. /*
  59.  *     D_GETPATH
  60.  *
  61.  *     this routine is called to get a path packet of the specified type
  62.  *     from the port.  it thens calls the routine to decode it.
  63.  *
  64.  *     type -- the type of path packet we're looking for
  65.  *
  66.  *     timeout -- the amount of time that we're willing to wait to receive
  67.  *                it
  68.  *
  69.  *     maxleng -- pointer to where the maximum packet length specified in the
  70.  *                packet should be loaded
  71.  *
  72.  *     bitvector -- pointer to the bit vector where the illegal character
  73.  *                  bit vector should be placed
  74.  */
  75.  
  76. d_getpath(type, maxleng, bitvector)
  77.   char  type;
  78.   int  *maxleng;
  79.   unsigned short bitvector[];
  80.     {
  81.     register int  length, result;
  82.     char  packet[MAXPACKET + 2];
  83.  
  84.     length = d_watch(packet, type);
  85.  
  86.     if (length < 0)
  87.       return(length);
  88.  
  89. /*  send the packet to the decoding routine  */
  90.  
  91.     result = d_setpath(packet, length, maxleng, bitvector);
  92.     return(result);
  93.     }
  94.  
  95. /*
  96.  *     D_SETPATH
  97.  *
  98.  *     this routine decodes the text portion of a path packet and loads
  99.  *     the given variables
  100.  *
  101.  *     packet -- pointer to the path packet
  102.  *
  103.  *     length -- length of the path packet
  104.  *
  105.  *     maxleng -- pointer to where the maximum packet length given in the
  106.  *                packet should be loaded
  107.  *
  108.  *     bitvector -- pointer to the bit vector to be loaded
  109.  */
  110.  
  111. d_setpath(packet, length, maxleng, bitvector)
  112.   char  packet[];
  113.   int  length, *maxleng;
  114.   unsigned short bitvector[];
  115.     {
  116.     extern int  d_errno;
  117.     register int  dig1, dig2, max;
  118.     int  result;
  119.  
  120. /*  check the length  */
  121.  
  122.     if (length != LPATH)
  123.       {
  124. #ifdef D_LOG
  125.       d_log("d_setpath", "bad length (%d) path packet received", length);
  126. #endif D_LOG
  127.       d_errno = D_PATHERR;
  128.       return(D_FATAL);
  129.       }
  130.  
  131. /*  decode the maximum packet length  */
  132.  
  133.     dig1 = d_fromhex(packet[TEXTOFF]);
  134.     dig2 = d_fromhex(packet[TEXTOFF + 1]);
  135.  
  136.     if ((dig1 < 0) || (dig2 < 0))
  137.       {
  138. #ifdef D_LOG
  139.       d_log("d_setpath", "bad hex character in path (length '%c%c', type '%c')",
  140.           dig1, dig2, packet[TYPEOFF]);
  141. #endif D_LOG
  142.       d_errno = D_PATHERR;
  143.       return(D_FATAL);
  144.       }
  145.  
  146.     max = (dig1 << 4) | dig2;
  147.  
  148.     if ((max < LPATH) || (max > MAXPACKET))
  149.       {
  150. #ifdef D_LOG
  151.       d_log("d_setpath", "bad max packet size (%d) in path packet, type '%c'",
  152.           max, packet[TYPEOFF]);
  153. #endif D_LOG
  154.       d_errno = D_PATHERR;
  155.       return(D_FATAL);
  156.       }
  157.  
  158.     *maxleng = max;
  159.  
  160. /*  decode the illegal character string  */
  161.  
  162.     result = d_bldcvec(&packet[TEXTOFF + 2], bitvector);
  163.     return(result);
  164.     }
  165.